<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<script>

function closeWindow() {

    if(window.opener.document.forms[0].name == 'customerForm'){
        window.opener.refresh();
    }
    window.close();
}

var saved = false;
function save(){

	var form = document.salesPerson_relationship;
    var pa=document.getElementById("errors");
    pa.innerHTML = "";
    if (typeof document.salesPerson_relationship.salesPerson != "undefined" )
    {
        form.action.value = "saveSalesPersons";
        if( saved == false)
        {
            saved=true;
            addOptionElementForParentWindow();
            form.submit();
        }
    }
    else
    {
        pa.innerHTML = "Could not save because no <bean:message key="label.sales.quotation.salesPerson"/> are exists";
    }
}
function reset(){
    document.salesPerson_relationship.reset();
}

function addSalesPerson()
{
    var LeftPos=(screen.width)?(screen.width-900)/2:100;
    var TopPos=(screen.height)?(screen.height-450)/2:100;

    newWindow = window.open ('<%=chipTracContext%>/addNewSalesPerson.do?','salesPersons','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=700,height=550,Left= '+LeftPos+',top='+TopPos+',resizable=no');
    if(!newWindow.opener) {newWindow.opener = window}
    newWindow.focus();
    //document.customerForm['customer.salesPerson'].value = " ";
}

function showErrorReportPage()
{
    newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
    newWindow.focus();
}

function addOptionElementForParentWindow()
{

    var salesPerson = "" ;

    if (typeof document.salesPerson_relationship.salesPerson.length == "undefined" )
    {
            salesPerson = document.salesPerson_relationship.salesPerson.value;

            window.opener.deleteAllOptions();
            window.opener.addOptionToSelect ( "----select----" , "" );
            if( document.salesPerson_relationship.odmId.value > 0 )
            {
                window.opener.addOptionToSelect ( "---For Customer---" , "-1" );
            }
            if (document.salesPerson_relationship.salesPersonId.checked != false)
            {
                window.opener.addOptionToSelect ( salesPerson , salesPerson );
            }
    }
    else
    {

        window.opener.deleteAllOptions();
        window.opener.addOptionToSelect ( "----select----" , "" );
        if( document.salesPerson_relationship.odmId.value > 0 )
        {
            window.opener.addOptionToSelect ( "---For Customer---" , "-1" );
        }
        for( var i=0; i < document.salesPerson_relationship.salesPerson.length; i++ )
        {
            if (document.salesPerson_relationship.salesPersonId[i].checked != false)
            {
                salesPerson = document.salesPerson_relationship.salesPerson[i].value;
                window.opener.addOptionToSelect ( salesPerson , salesPerson );
            }
        }

    }
    //to insert the odm sales persons in to parent window list box
    if( document.salesPerson_relationship.odmId.value > 0 )
    {
        if (typeof document.salesPerson_relationship.odmSalesPerson.length == "undefined" )
        {
                salesPerson = document.salesPerson_relationship.odmSalesPerson.value;

                window.opener.addOptionToSelect ( "---For <bean:message key="label.sales.endCustomer" /> ---" , "-2" );
                if (document.salesPerson_relationship.odmSalesPersonId.checked != false)
                {
                    window.opener.addOptionToSelect ( salesPerson , salesPerson );
                }
        }
        else
        {

            window.opener.addOptionToSelect ( "---For <bean:message key="label.sales.endCustomer" /> ---" , "-2" );
            for( var i=0; i < document.salesPerson_relationship.odmSalesPerson.length; i++ )
            {
                if (document.salesPerson_relationship.odmSalesPersonId[i].checked != false)
                {
                    salesPerson = document.salesPerson_relationship.odmSalesPerson[i].value;
                    window.opener.addOptionToSelect ( salesPerson , salesPerson );
                }
            }
        }
    }
}


</script>

<TABLE cellSpacing=0 cellPadding=0 width="40%" border="0">
  <TBODY>
  <TR>

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>

<!-- from here your body starts -->

<center><span class="NArialW">Customer/<bean:message key="label.sales.quotation.salesPerson"/></span></center>

<%--<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>--%>
<html:form name="salesPerson_relationship" method="post" action="/customerSalesPersonRelationship.do" scope="request" type="com.scalar.chiptrack.sales.forms.AddNewSalesPersonForm" onsubmit="">
<table border="0" width="85%" cellpadding=0 cellspacing=0 align="center">
 <tr>
	<td align=right>
		<a href="javascript:closeWindow();"  onMouseOver="window.status='Click here to close this window';return true"><font class='NArialL'><b>[Close this window]</b></font></a>
	</td>
</tr>
<tr>
	<td class="NArialL">
		<chiptrack:info styleClass="NArialL" />
		<chiptrack:errors styleClass="NArialL" />
        <FONT id="errors" color='FF0000'></FONT>
	</td>
</tr>

<tr class="NArialL"><td>&nbsp;</td></tr>
<tr class="NArialL"><td align="center">Customer Name:&nbsp;&nbsp;<%=(String)request.getAttribute("customerName")%></td></tr>
<tr class="NArialL"><td>&nbsp;</td></tr>

<tr><td>
<table width="75%" class="NArialL" align="center" border="0" >
<tr bgcolor='#993333' class="NArialL"><td><font color='#FFFFFF'>List of <bean:message key="label.sales.quotation.salesPerson"/></font></td></tr>
<logic:iterate id="SalesPerson" name="salesPersonsList">
	<tr>
		<td>
			<input type="checkbox" name="salesPersonId"
			value="<bean:write name="SalesPerson" property="salesPersonId" />"
            <bean:write name="SalesPerson" property="flag" />>
			<bean:write name="SalesPerson" property="salesPerson" />
            <input type=hidden name='salesPerson' value='<bean:write name="SalesPerson" property="salesPerson" />'/>
		</td>
	</tr>
</logic:iterate>

<tr><td>&nbsp;</td></tr>
</table>
<logic:present name="odmSalesPersonsList">
<tr class="NArialL"><td>&nbsp;</td></tr>
<tr class="NArialL"><td align="center"><bean:message key="label.sales.endCustomer" /> Name:&nbsp;&nbsp;<%=(String)request.getAttribute("odmName")%></td></tr>
<tr class="NArialL"><td>&nbsp;</td></tr>

<tr><td>
<table width="75%" class="NArialL" align="center" border="0" >
<tr bgcolor='#993333' class="NArialL"><td><font color='#FFFFFF'>List of <bean:message key="label.sales.quotation.salesPerson"/></font></td></tr>
<bean:size id="SalesPersonsListSize" name="odmSalesPersonsList" />
<logic:iterate id="SalesPerson" name="odmSalesPersonsList">
	<tr>
		<td>
			<input type="checkbox" name="odmSalesPersonId"
			value="<bean:write name="SalesPerson" property="salesPersonId" />"
            <bean:write name="SalesPerson" property="flag" />>
			<bean:write name="SalesPerson" property="salesPerson" />
            <input type=hidden name='odmSalesPerson' value='<bean:write name="SalesPerson" property="salesPerson" />'/>
		</td>
	</tr>
</logic:iterate>
</table>
</logic:present>

<tr><td>&nbsp;</td></tr>

<tr><td width="20%" colspan="2"><font class="NArialL">Please <a styleClass="leftsection" href="javascript:addSalesPerson()" onmouseover="window.status='Click to Add Sales Person';return true" onmouseout="window.status='';return true">
        Click here</a>&nbsp;to Add/Edit <bean:message key="label.sales.quotation.salesPerson"/>
        </font></td></tr>

<tr><td>&nbsp;</td></tr>
<tr>
<td align="center">
<%--<logic:greaterThan name="SalesPerson" value="0" >--%>
    <a href="javascript:save()" onmouseover="window.status='Click here to Save <bean:message key="label.sales.quotation.salesPerson"/> Relationships';return true" onmouseout="window.status='';return true" title="Click here to Save Sales Person Relationships"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></a>
    &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:reset()" onmouseover="window.status='Click here to Reset Sales Person Relationships';return true" onmouseout="window.status='';return true" title="Click here to Reset Sales Person Relationships"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>
<%--</logic:greaterThan>--%>
</td>
</tr>
<tr class="NArialL"><td>&nbsp;</td></tr>
<tr class="NArialL"><td>&nbsp;</td></tr>
<tr><td align="center"><a href="javascript:closeWindow();" onMouseOver="window.status='Click here to close this window';return true" onmouseout="window.status='';return true" ><font class='NArialL'>Close this window</font></a></td></tr>
<%-- <tr><td align="center"><chiptrack:linkCustomer page="/customerRelationship.do?action=EditCustomer"  onmouseover="window.status='Click here to close this window';return true" onmouseout="window.status='';return true">Close this window</chiptrack:linkCustomer></td></tr>--%>

</td></tr>
<tr><td>&nbsp;</td></tr>
</table>

<input type="hidden" name="customerId" value="<%= (String)request.getParameter("customerId")%>">
<input type="hidden" name="customerName" value="<%= (String)request.getParameter("customerName")%>">
<input type="hidden" name="odmId" value="<%= request.getParameter("odmId") != null ? request.getParameter("odmId") : "" %>">
<input type="hidden" name="action" value="">

</html:form>
</TR>
</TABLE>
</body>
</html>